/******************************************************************************
Copyright:
2009 Jens Collin (jens.collin@dinomin.com)

This file is part of Envox Decompiler.

Envox Decompiler is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Envox Decompiler is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with KitchenOS.  If not, see <http://www.gnu.org/licenses/>.

******************************************************************************/
using System;

namespace EnvoxDecompiler
{
	/// <summary>
	/// Summary description for DbParameter.
	/// </summary>
	public class DbParameter
	{

		enum PARAM_TYPE
		{
			InputOnly = 1,
			InputOutput = 2,
			OutputOnly = 4 // Also same as 'ReturnValue = 5', can't differentiate the two.
		}

		private PARAM_TYPE _parameterType;
		private string _input;
		private string _output;

		/// <summary>
		/// Creates a db-parameter object based on inputs. If either one is null,
		/// it affects the type of parameter that will be created.
		/// </summary>
		/// <param name="input"></param>
		/// <param name="output"></param>
		public DbParameter(string input, string output)
		{
			_input = input;
			_output = output;

			if (_input != null && _output == null)
			{
				_parameterType = PARAM_TYPE.InputOnly;
			}
			else if (_input == null && _output != null)
			{
				_parameterType = PARAM_TYPE.OutputOnly;
			}
			else if (_input != null && _output != null)
			{
				_parameterType = PARAM_TYPE.InputOutput;
			}
			else
			{
				Trace.Debug("DbParameter: Got both input and output as null!");
				throw new UnimplementedException("DbParameter, both input and output cannot be null!");				
			}
		}

		/// <summary>
		/// Trace out through debug-channel this db-parameter.
		/// </summary>
		public void Dump()
		{
			Trace.Debug("DbParameter: type: " + _parameterType + " input = " + _input + ", output = " + _output);
		}
	

		/// <summary>
		/// Assemble this parameter in xml form.
		/// </summary>
		/// <returns>XML data representing this db-parameter</returns>
		public string GetXML()
		{
			string ret = "<SQLStatementParameter";
			ret += " inputValue=\"" + Utils.XmlString(_input) + "\"";
			ret += " outputValueVar=\"" + Utils.XmlString(_output) + "\"";
			ret += " type=\"" + (int)_parameterType + "\"";
			ret += " dataType=\"-1\"";
			ret += "/>";
			return ret;
		}

	}
}
